home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Newton Sample Code 1.2 / Proto Templates / Expando Time-2 / ExpandoTime.text < prev    next >
Encoding:
Text File  |  1994-03-07  |  4.0 KB  |  153 lines  |  [TEXT/MPS ]

  1. // Copyright © 1993,4 Apple Computer, Inc. All rights reserved
  2.  
  3. // application constants
  4. constant kAppSymbol := '|ExpandoTime:PIEDTS| ;
  5. constant kAppString := "Expando Time";
  6.  
  7. // for application size
  8. constant kMaxWidth := 240 ;    // MP100 size
  9. constant kMaxHeight := 336 ;    // MP100 size
  10. // ---- End Project Data ----
  11.  
  12.  
  13. // ---- File Expando Time.t ----
  14.  
  15. // Before Script for "_view000"
  16. // Copyright © 1993,4 Apple Computer, Inc. All rights reserved
  17.  
  18. _view000 :=
  19.    {viewBounds: {left: 0, top: 0, right: 240, bottom: 336},
  20.     viewSetupFormScript:
  21.       func()
  22.       begin
  23.           // resize application to display, but
  24.           // make sure it is no bigger than
  25.           // a MessagePad
  26.           b := GetAppParams() ;
  27.           viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop,
  28.                               MIN(b.appAreaWidth, kMaxWidth),
  29.                               MIN(b.appAreaHeight, kMaxHeight));
  30.       end,
  31.     _proto: protoApp
  32.    };
  33.  
  34. _view001 := /* child of _view000 */
  35.    {
  36.     viewSetupFormScript:
  37.       func()
  38.       begin
  39.           // setup the target slot, just create a temporary
  40.           // frame to edit
  41.          self.target := {time1: Time(), time2: 56345760};
  42.       
  43.           // now setup the lines array to have 2 time protos
  44.           lines := [
  45.               {_proto: pt_protoTimeExpando,
  46.                label: "Now",
  47.                path: 'time1},
  48.               {_proto: pt_protoTimeExpando,
  49.                label: "Then",
  50.                path: 'time2}] ;
  51.       
  52.           // set the number of lines to display
  53.           numLines := Length(lines) ;
  54.       
  55.           // finaly, call inherited method to make sure
  56.           // everything gets setup correctly
  57.           inherited:?viewSetupFormScript() ;
  58.       end,
  59.     editWidth: 150,
  60.     editHeight: 50,
  61.     viewBounds: {left: 26, top: 42, right: 218, bottom: 258},
  62.     flushEdits:
  63.       func()
  64.       begin
  65.           nil
  66.       end,
  67.     lines: nil,
  68.     numlines: 2,
  69.     _proto: protoExpandoShell
  70.    };
  71.  
  72.  
  73.  
  74. // After Script for "_view000"
  75. thisView := _view000;
  76. // set the title of this application
  77. thisView.title := kAppString ;
  78.  
  79.  
  80. // ---- Beginning of non-used User Protos ----
  81.  
  82. // ---- File protoTimeExpando ----
  83.  
  84. // Before Script for "_userproto000"
  85. // Copyright © 1993,4 Apple Computer, Inc. All rights reserved
  86.  
  87. _userproto000 :=
  88.    {viewBounds: {left: 3, top: 3, right: 5, bottom: 5},
  89.     entryFlags: 1097233,
  90.     textChanged:
  91.       // do some error checking on the input
  92.       func()
  93.       begin
  94.           // be nice and let text expando do what it needs to
  95.           inherited:?textChanged();
  96.       
  97.           // now do some error checking
  98.          // now set target slot to a number
  99.          local num :=  StringToTime(entryLine.text);
  100.       
  101.          // the text could be bogus, so num may be nil
  102.          // set it to a default
  103.           // WARNING: ickky error feedback!
  104.          if not num then
  105.           begin
  106.               if not StrEqual(entryLine.text, "") then
  107.               begin
  108.                   local errorText := "'" & entryLine.Text & "' is not a valid time" ;
  109.                   :Notify(kNotifyAlert, EnsureInternal(kAppString),
  110.                               EnsureInternal(errorText)) ;
  111.                   // set the text back to what it was before the error
  112.                   // can do this because proto will add undo actions
  113.                   AddDeferredAction(func() PostCommand('application, aeUndo), []);
  114.               end;
  115.             num := 0 ;
  116.           end;
  117.       
  118.          // finaly, write the data to the target
  119.          target.(path) := num ;
  120.       
  121.       end,
  122.     setup2:
  123.       func(target)
  124.       begin
  125.          // this function gets called to figure out what
  126.          // text to show for the value in the collapsed
  127.          // state
  128.          // just return a string
  129.       
  130.          if target then
  131.             HourMinute(target.(path));
  132.       end,
  133.     textSetup:
  134.       // show the correct text in the expanded entry
  135.       func()
  136.       begin
  137.           // let the expando item to its work
  138.           inherited:textSetup();
  139.       
  140.           // now get the right text
  141.           HourMinute(target.(path));
  142.       end,
  143.     _proto: protoTextExpando
  144.    };
  145.  
  146.  
  147. // ---- End of non-used User Protos ----
  148.  
  149.  
  150.  
  151. // ---- Beginning of section for non used Layout files ----
  152.  
  153. // End of output